home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-05-15 | 5.5 KB | 178 lines |
- import ComponentApp;
-
- public class SitemapComp extends ComponentApp
- {
- int idApplet[];
- int idImage;
- int idScript;
- DAssetManager assMan;
- String m_codebase;
- DDrawPicture thePicture;
-
- public String onInstall(DAssetManager cam, String codebase)
- {
- m_codebase = codebase;
- assMan = cam;
- return "Site Mapper";
- }
-
- public void onInspect(CStringArray Names,CStringArray Types)
- {
- Names.Set("Image");
- Types.Set(typeImage);
- }
-
- public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp)
- {
- if (Get == 1) // return a value
- {
- if (Event.compareTo("Image")==0)
- {
- return Integer.toString(idImage);
- }
- }
- else // user set a value
- {
- if (Event.compareTo("Image")==0)
- {
- assMan.RemoveAsset(idImage);
- idImage = Integer.parseInt(Value,10);
- thePicture.setImageFile(assMan.GetAssetLocation(idImage, IAssetContext.Preview, IFileNameStyle.DosName));
- }
- }
- return "";
- }
-
- public void onDrop(IDLayout layout, IDRect r, int fDrop)
- {
- if (fDrop == ActivateState.Drop) // the first time the component is dropped
- {
- idApplet = new int[12];
- idImage = assMan.AddAsset(m_codebase+"Sitemapper.gif",IAssetType.Image,"");
-
- idApplet[0] = assMan.AddAsset(m_codebase + "Sitemapper.class",IAssetType.Applets,"");
- idApplet[1] = assMan.AddAsset(m_codebase + "button_panel.class",IAssetType.Applets,"");
- idApplet[2] = assMan.AddAsset(m_codebase + "check_box_panel.class",IAssetType.Applets,"");
- idApplet[3] = assMan.AddAsset(m_codebase + "image_button.class",IAssetType.Applets,"");
- idApplet[4] = assMan.AddAsset(m_codebase + "nav_canvas.class",IAssetType.Applets,"");
- idApplet[5] = assMan.AddAsset(m_codebase + "outline_list.class",IAssetType.Applets,"");
- idApplet[6] = assMan.AddAsset(m_codebase + "search_panel.class",IAssetType.Applets,"");
- idApplet[7] = assMan.AddAsset(m_codebase + "tree_entry.class",IAssetType.Applets,"");
- idApplet[8] = assMan.AddAsset(m_codebase + "tree_grid_builder.class",IAssetType.Applets,"");
- idApplet[9] = assMan.AddAsset(m_codebase + "web_structure_builder.class",IAssetType.Applets,"");
- idApplet[10] = assMan.AddAsset(m_codebase + "Sitemapper.cab",IAssetType.Applets,"");
- idApplet[11] = assMan.AddAsset(m_codebase + "Sitemapper.zip",IAssetType.Applets,"");
-
-
- thePicture = new DDrawPicture();
- thePicture.SetPositionRect(r.getLeft(), r.getTop(), r.getRight(), r.getBottom());
- String bmpFile = assMan.GetAssetLocation(idImage,IAssetContext.Local,1);
- thePicture.setImageFile(bmpFile);
-
- thePicture.setHTMLBefore("<a href =\"#\" target=_self onclick=\"go();\">");
- thePicture.setHTMLAfter("</a>");
- layout.AddObject(thePicture);
- idScript = assMan.AddAsset("script_layout", IAssetType.JavaScript,"");
- IDLayout currentILayout = thePicture.getLayout();
- IDSite site = currentILayout.getSite();
- site.setGenerateSiteMap(true);
- }
- }
-
- public void onPublish(DAssetManager asm, int context)
- {
- updateSitemapperHTML(context);
- DFile file = new DFile();
-
- IDLayout currentILayout = thePicture.getLayout();
- String homePath = currentILayout.GetHomePath();
-
-
- if (homePath.compareTo(".\\") == 0 || homePath.compareTo(".:") == 0) // component is on the home page
- {
- file.Open(m_codebase + "script_layout.txt", FileOpenMode.modeRead);
- }
- else // component is on sub-page
- {
- file.Open(m_codebase + "script_layout2.txt", FileOpenMode.modeRead);
- }
-
- String scriptText = file.ReadString(10000);
- file.Close();
- assMan.InsertScript("script_layout", scriptText);
- }
-
- public void updateSitemapperHTML(int context)
- {
- DMessageBox d = new DMessageBox();
- DFile dummy=new DFile();
- String pathChar = dummy.GetPathChar();
- String fileLocation=dummy.getExeLocation()+"NetObjects System" + pathChar;
- String sitemapper1 = (fileLocation + "Sitemapper.part1");
- String sitemapper2 = (fileLocation + "Sitemapper.part2");
- String sitemapperHTML = (fileLocation + "Sitemapper.html");
- DFile inFile= new DFile();
- DFile outFile = new DFile();
- if(outFile.Open(sitemapperHTML, FileOpenMode.modeWrite|FileOpenMode.modeCreate)==false)
- {
- d.Alert("Unable to open file "+sitemapperHTML+"\r\n");
- return;
- }
- if(inFile.Open(sitemapper1, FileOpenMode.modeRead)==false)
- {
- d.Alert("Unable to open file "+sitemapper1+"\r\n");
- return;
- }
-
- String buffer;
- buffer=inFile.ReadString(10000);
- outFile.WriteString(buffer,-1);
- inFile.Close();
-
- if (context == IAssetContext.Local || context == IAssetContext.Preview)
- {
- m_codebase.replace('\\','/');
- outFile.WriteString(" CODEBASE=\"file:///"+m_codebase+"\"",-1);
- }
-
- if(inFile.Open(sitemapper2, FileOpenMode.modeRead)==false)
- {
- d.Alert("Unable to open file "+sitemapper2+"\r\n");
- return;
- }
-
- buffer=inFile.ReadString(10000);
- outFile.WriteString(buffer,-1);
- inFile.Close();
- outFile.Close();
- }
-
- private void debug(String out)
- {
- DMessageBox d = new DMessageBox();
- d.Trace(out);
- }
-
- protected void finalize()
- {
- for (int i=0;i<12;i++)
- assMan.RemoveAsset(idApplet[i]);
- assMan.RemoveAsset(idImage);
- assMan.RemoveAsset(idScript);
- }
-
- public void onCopy()
- {
- assMan.CopyAsset(idImage);
- assMan.CopyAsset(idScript);
-
- int tempIdApplet[] = new int[12];
-
- for (int i=0; i < 12; i++)
- {
- tempIdApplet[i] = idApplet[i];
- assMan.CopyAsset(idApplet[i]);
- }
- idApplet = tempIdApplet;
- }
- }